
import { getSelectKey } from './utils';
/**
 * 处理树形结构-点击复选框后子节点复选框勾选状态
 * @param  { Arrary } children: 当前点击复选框的子节点数据
 * @param  { Object } selectedEntityMap: 右侧已选数据的UuidMap
 * 返回值： Object: { hasChecked, nodesNum, checkedNodesNum }
 * @param  { Array } nodes  未勾选的子节点集合
 * @param  { Number } nodesNum  共有节点数量
 * @param  { Number } checkedNodesNum  已选节点数量
 */
export const nodeChildrenCheck = (children, selectedEntityMap) => {
	let nodes = [];
	let nodesNum = 0;
	let checkedNodesNum = 0;
	if (!children || children.length === 0) {
		return nodes;
	}
	for (let child of children) {
		nodesNum++;
		nodes = [...nodes];
		let uuid = getSelectKey(child);
		if (selectedEntityMap[uuid]) {
			checkedNodesNum++;
		} else {
			nodes.push(child);
		}
		nodeChildrenCheck(child.children, selectedEntityMap);
	}

	return { nodes, nodesNum, checkedNodesNum };
};
